package com.hy.admin.service.impl;

import com.hy.admin.dao.CourseLikeDao;
import com.hy.admin.entity.CourseLikeEntity;
import com.hy.admin.service.CourseLikeService;
import com.hy.core.response.ServicesResult;
import org.apache.commons.httpclient.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.List;

@Service
public class CourseLikeServiceImpl implements CourseLikeService {

    @Autowired
    private CourseLikeDao courseLikeDao;

    @Override
    public ServicesResult<Boolean> add(CourseLikeEntity courseLike) {
        ServicesResult<Boolean> servicesResult = new ServicesResult<>();
        //校验请求参数
        if (courseLike == null){
            servicesResult.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            servicesResult.setStatusMsg("请求报文有误");
            return servicesResult;
        }
        //校验必填参数
        if(courseLike.getCourseId() == null){
            servicesResult.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            servicesResult.setStatusMsg("courseId不能为空");
            return servicesResult;
        }
        if(courseLike.getMemberId() == null){
            servicesResult.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            servicesResult.setStatusMsg("memberId不能为空");
            return servicesResult;
        }
        Calendar cal = Calendar.getInstance();
        courseLike.setCreateTime(cal.getTime());
        courseLike.setUpdateTime(cal.getTime());
        //插入数据
        int result = courseLikeDao.insertSelective(courseLike);
        servicesResult.setResult(result == 1 ? true : false);
        return servicesResult;
    }
}
